home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / OptionsAutobanPage.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  4KB  |  124 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2007 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. #include "stdafx.h"
  20. #include "filezilla server.h"
  21. #include "OptionsDlg.h"
  22. #include "Options.h"
  23. #include "OptionsPage.h"
  24. #include "OptionsAutobanPage.h"
  25. #include "../OptionLimits.h"
  26.  
  27. #if defined(_DEBUG) && !defined(MMGR)
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Dialogfeld COptionsMisc 
  35.  
  36.  
  37. COptionsAutobanPage::COptionsAutobanPage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  38.     : COptionsPage(pOptionsDlg, COptionsAutobanPage::IDD, pParent)
  39. {
  40.     //{{AFX_DATA_INIT(COptionsAutobanPage)
  41.     m_enable = false;
  42.     m_attempts = _T("5");
  43.     m_time = _T("1");
  44.     m_type = 0;
  45.     //}}AFX_DATA_INIT
  46. }
  47.  
  48.  
  49. void COptionsAutobanPage::DoDataExchange(CDataExchange* pDX)
  50. {
  51.     COptionsPage::DoDataExchange(pDX);
  52.     //{{AFX_DATA_MAP(COptionsAutobanPage)
  53.     DDX_Check(pDX, IDC_AUTOBAN, m_enable);
  54.     DDX_Text(pDX, ID_ATTEMPTS, m_attempts);
  55.     DDV_MaxChars(pDX, m_attempts, 3);
  56.     DDX_Text(pDX, ID_BANTIME, m_time);
  57.     DDV_MaxChars(pDX, m_time, 3);
  58.     DDX_Radio(pDX, IDC_BANTYPE1, m_type);
  59.     //}}AFX_DATA_MAP
  60. }
  61.  
  62.  
  63. BEGIN_MESSAGE_MAP(COptionsAutobanPage, COptionsPage)
  64.     //{{AFX_MSG_MAP(COptionsAutobanPage)
  65.     //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Behandlungsroutinen fⁿr Nachrichten COptionsAutobanPage
  70.  
  71. BOOL COptionsAutobanPage::OnInitDialog() 
  72. {
  73.     COptionsPage::OnInitDialog();
  74.     
  75.     return TRUE;  // return TRUE unless you set the focus to a control
  76.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  77. }
  78.  
  79. void COptionsAutobanPage::LoadData()
  80. {
  81.     m_enable = m_pOptionsDlg->GetOptionVal(OPTION_AUTOBAN_ENABLE) ? true : false;
  82.     m_attempts.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_AUTOBAN_ATTEMPTS)));
  83.     m_time.Format(_T("%d"), static_cast<int>(m_pOptionsDlg->GetOptionVal(OPTION_AUTOBAN_BANTIME)));
  84.     m_type = m_pOptionsDlg->GetOptionVal(OPTION_AUTOBAN_TYPE) ? 1 : 0;
  85. }
  86.  
  87. void COptionsAutobanPage::SaveData()
  88. {
  89.     m_pOptionsDlg->SetOption(OPTION_AUTOBAN_ENABLE, m_enable ? 1 : 0);
  90.     m_pOptionsDlg->SetOption(OPTION_AUTOBAN_ATTEMPTS, _ttoi(m_attempts));
  91.     m_pOptionsDlg->SetOption(OPTION_AUTOBAN_BANTIME, _ttoi(m_time));
  92.     m_pOptionsDlg->SetOption(OPTION_AUTOBAN_TYPE, (m_type == 0) ? 0 : 1);
  93. }
  94.  
  95. BOOL COptionsAutobanPage::IsDataValid()
  96. {
  97.     if (!UpdateData(TRUE))
  98.         return FALSE;
  99.  
  100.     if (!m_enable)
  101.         return TRUE;
  102.  
  103.     int attempts = _ttoi(m_attempts);
  104.     if (attempts < OPTION_AUTOBAN_ATTEMPTS_MIN || attempts > OPTION_AUTOBAN_ATTEMPTS_MAX)
  105.     {
  106.         CString s;
  107.         s.Format(_T("\"Attempts\" has to be a number between %d and %d."), OPTION_AUTOBAN_ATTEMPTS_MIN, OPTION_AUTOBAN_ATTEMPTS_MAX);
  108.         AfxMessageBox(s);
  109.         return FALSE;
  110.     }
  111.  
  112.     if (!m_type)
  113.     {
  114.         int time = _ttoi(m_time);
  115.         if (time < 1 || time > 999)
  116.         {
  117.             AfxMessageBox(_T("Ban time has to be a number between 1 and 999"));
  118.             return FALSE;
  119.         }
  120.     }
  121.  
  122.     return TRUE;
  123. }
  124. \